﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Simulacion.NumberGenerator;

namespace Simulacion.Distributions
{
    /// <summary>
    ///  Generic class of the Weibull distribution.
    /// </summary>
    class Weibull
    {
        public static double fWeibull(double x, double xDis, double alpha, double beta, double gamma)
        {
            return (alpha / beta) * Math.Pow(((x - xDis) - gamma) / beta, alpha - 1) * Math.Exp(-1.0 * Math.Pow(((x - xDis) - gamma) / beta, alpha));
        }

        /// <summary>
        /// Gets the value using the Weibull distribution.
        /// </summary>
        /// <returns>The value of the distribution.</returns>
        public static double GetDistributionValue(double lowerBound, double upperBound, double xDisplacement, double alpha, double beta, double gamma)
        {
            double _result, R;
            do
            {
                R = Generator.NextNumber;
                _result = (beta * Math.Pow(-1.0 * Math.Log(1.0 - R), 1.0 / alpha) + gamma) + xDisplacement;
            } while (_result < lowerBound || _result > upperBound);

            return _result / 7;
        }
    }
}
